package com.example.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class userService {
    private static final Logger log = LoggerFactory.getLogger(userService.class);
    /**
     * 通过注解执行异步任务
     */
    @Async
    public void sayHello() {
        long beginTime = System.currentTimeMillis();
        try {
            Thread.sleep(3000);

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long endTime = System.currentTimeMillis();
        long duringTime = endTime - beginTime;
        log.info("sssss");
        System.out.println("异步消耗时间："+duringTime+"线程名称："+Thread.currentThread().getName());
    }
}
